package com.xy.controller.approval;

import com.xy.api.model.dto.approval.ApprovalTemplateDTO;
import com.xy.api.model.response.R;
import com.xy.api.model.response.Rows;
import com.xy.api.service.approval.IApprovalTemplateService;
import com.xy.controller.BaseController;
import com.xy.api.model.request.approval.ApprovalTemplateRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/approval/template")
public class ApprovalTemplateController extends BaseController {

    @Autowired
    private IApprovalTemplateService approvalTemplateService;

    @PostMapping("/edit")
    public R edit(@RequestBody ApprovalTemplateDTO request) {
        approvalTemplateService.edit(request);
        return success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody ApprovalTemplateRequest request) {
        approvalTemplateService.delete(request);
        return success();
    }

    @PostMapping("/list")
    public R list(@RequestBody ApprovalTemplateRequest request) {
        Rows<ApprovalTemplateDTO> rows = approvalTemplateService.list(request);
        return success(rows);
    }

    @PostMapping("/detail")
    public R detail(@RequestBody ApprovalTemplateRequest request) {
        ApprovalTemplateDTO approvalTemplate = approvalTemplateService.findDetailById(request.getApprovalTemplateId());
        return success(approvalTemplate);
    }

}
